(function (G) {
    const javaUrl = G.Storage.get('JAVAURL')
    G.vue({
        data: {
            APIURL: G.Storage.get('APIURL'),
            begin_time: null,
            fileId: '',
            id: '',
            initialTime: 0,
            timer: null
        },
        methods: {
            //安全学习阅读统计
            stduyStatic() {

                const {
                    id,
                    begin_time,
                    initialTime,
                } = this.data
           console.log(initialTime,'initialTime')
                let data = {
                    emp_id: id,
                    learning_length: initialTime,
                    begin_time

                }
                G.post(javaUrl + '/security/addSl', data)
            },
            // 开始播放
            bindplay(e) {
                const {
                    begin_time
                } = this.data
                if (!begin_time) {
                    this.setData({
                        begin_time: G.date(-(-new Date())).Format('yyyy-MM-dd hh:mm:ss')
                    })
                    this.stduyStatic()
                }
                console.log(e, '开始播放')
            },
            bindended(e) {
                const {id} = this.data
                wx.removeStorageSync('video' + id)
                console.log(e, '当播放到末尾时触发')
                this.getPlayTime()
                this.stduyStatic()
              
            },
            bindpause(e) {

                this.getPlayTime()
                this.stduyStatic()
            },
            videoErrorCallback(e) {
                console.log(e, '视频出错')
           
               
            },
            bindtimeupdate(e) {
                console.log(e.detail.currentTime, '播放进度')
                const {
                    id
                } = this.data
                    wx.setStorageSync('video' + id, e.detail.currentTime)
            },
            onHide (){
                this.getPlayTime()
                this.stduyStatic()
            },
            getPlayTime (){
                const {id} = this.data
                this.setData({
                    initialTime:wx.getStorageSync('video' + id) || 0
                })
                
            }
        },
        mounted(opt) {
            this.setData({
                id: opt.id,
                fileId: opt.fileid,

            })
            wx.setNavigationBarTitle({
                title: opt.title,
            })
            const initialTime = wx.getStorageSync('video'+ opt.id)
            if (initialTime) {
                this.setData({
                    initialTime
                })
              
            }
        }
    })
})(wx.$)